package com.qf.controller;

import com.qf.pojo.User;
import com.qf.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;

/**
 * @Description: 公用常量
 * @Data: 2022/9/14 20:17
 * @Pacakge: com.qf.controller
 * @ClassName: UserController
 * @Author: fan
 */
@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;
    @RequestMapping("/index")
    public String index(){
        return "index";
    }
    @RequestMapping("/login")
    public String login(User user, HttpSession httpSession){
       Boolean login =  userService.findUserName(user,httpSession);
       if (login){
            return "redirect:/student/findAll";
       }else{
           return "redirect:/user/index";
       }
    }
    @RequestMapping("/logOut")
    public String logOut(HttpSession httpSession){
        //清除session域的缓存对象
        httpSession.removeAttribute("user");
        return "redirect:/user/index";
    }
}
